<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="demo"></div>
    <button class="btn">点击</button>
</body>
<script>
    var demo = document.getElementById('demo');
    var btn = document.getElementsByClassName("btn")[0];

    // var a = 10;
    // a += 5;
    // a *= 5;

    // btn.onclick = function () {
    //     var req = new XMLHttpRequest();  // 0

    //     req.open("get", "../data/1.json", true);  // 1

    //     req.send();  // 1

    //     req.onreadystatechange = function () {
    //         console.log("readyState", req.readyState);  // 2 3 4
    //         if (req.readyState == 4 && req.status == 200) {
    //             console.log(req.responseText);

    //             // 后端返回的响应数据 可以是 txt/html/xml/json数据(json字符串)
    //             // var result = req.responseText;
    //             // demo.innerHTML = result;
    //         }
    //     }

    // }

    var req = new XMLHttpRequest();  // 0

    req.open("get", "../data/1.js", true);  // 1

    req.send();  // 1

    req.onreadystatechange = function () {
        if (req.readyState == 4 && req.status == 200) {
            console.log(req.responseText);

            // 后端返回的响应数据 可以是 txt/html/xml/json数据(json字符串)
            // var result = req.responseText;
            // demo.innerHTML = result;
        }
    }

</script>

</html>